/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.dbg.model.content {
	import com.googlecode.milib.base.IChangable;
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.base.MLBroadcastClass;
	import com.googlecode.milib.vo.MLEventInfo;

	/**
	 * @author Marek Brun
	 */
	public class MLDBGValuesListModelItem extends MLBroadcastClass implements IMLBroadcasterListener {
		
		public const event_Changed : String = 'Changed';
		
		private var name:String='';
		private var value:String='';		private var count:uint=0;
		private var isCount:Boolean;
		public var index:Number;
		private var rawValue:*;
		
		public function MLDBGValuesListModelItem(isCount:Boolean=true, index:Number=0) {
			this.isCount=isCount;
			this.index=index;
		}
		
		public function setName(name:*):void {
			if(this.name==String(name)){ return; }
			this.name=String(name);
		}
		
		public function setValue(value:*=null):void {
			if(this.value==String(value)){ return; }
			if(rawValue && rawValue is IChangable){
				IChangable(rawValue).removeListener(this);
			}
			if(value!=null){
				this.value=String(value);
				rawValue=value;
				if(rawValue is IChangable){
					IChangable(rawValue).addListener(this);
				}
			}
			count++;
			broadcastEvent(event_Changed);
		}
		
		public function getName():String {
			return name;
		}
		
		public function getValue():String {
			if(isCount){
				return value+' *'+count;
			}
			return value;
		}
		
		public function getRawValue():* {
			return rawValue;
		}
		
//********************************************************************************************
//		events for MLDBGValuesListModelItem
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case rawValue:
					switch(ev.event) {
						case rawValue.event_Changed:
							broadcastEvent(event_Changed);
						break;
					}
				break;
			}
		}

		
	}
}
